<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/2/22 0022
 * Time: 21:49
 */
namespace app\admin\controller;
class Link extends Common
{
  protected  $db;
  public  function  __init(){
      $this->db=new \system\model\Link();
  }
  public function index(){
      $oldData=Db::table('link')->get();
      View::with('oldData',$oldData);
      return view();
  }
    /**
     * 添加超链接
     * @return mixed
     */
  public function  addLink(){
      if(IS_POST){
           if($this->db->addLink()){
               message('超链接添加成功',u('index'),'success',2);
           }
          message('超链接添加失败','back','error',2);
      }
      return view();
  }

    /**
     * 编辑超链接
     */
  public function  editLink(){
      if(IS_POST){
         if($this->db->editLink()){
             message('修改超链接成功',u('index'),'success');
         }
          message('修改超链接失败','back','error');
      }
      $lid=q('get.lid');
      $oldData=Db::table('link')->where('lid',$lid)->first();
      View::with('oldData',$oldData);
      return view();
  }
  /**
   * 删除超链接
   */
  public function  delLink(){
      if(IS_AJAX){
          $lid=$_POST['lid'];
          $res=Db::table('link')->where('lid',$lid)->delete();
//             message('删除成功',u('index'),'success',2);
          if($res){
              return message('删除超链接成功','back','success');exit;
          }
          return message('删除超链接失败','back','error');exit;
      }
  }
}